<?php
/**
 * StudentClass
 * @property	int		$id
 * @property	string	$name
 * @property	string	$grade
 * @property    string  $collegeId
 * @property	string	$created
 * @property	string	$updated
 */
class StudentClass extends Node {
    public static function option() {
        return array(
            'table' => 'Class',
            'key' => 'id',
            'columns' => array(
                'id' => 'id',
                'name' => 'name',
                'grade' => 'grade',
                'collegeId' => 'college_id',
                'created' => 'created',
                'updated' => 'updated',
                'attributeData' => 'attributes',
            ));
    }

    public static function attributesList() {
        return [
            'id',
            'name',
            'grade',
            'collegeId',
        ];
    }

    /**
     * @return College
     */
    public function college() {
        return College::load($this->collegeId);
    }

    public function remove() {
        /**
         * @var Student $student
         * @var CourseSelection $courseSelection
         */
        $students = Student::find(new Query('classId', $this->id), ['nolimit' => 1]);
        foreach ($students as $student) {
            $courseSelections = CourseSelection::find(new Query('studentId', $student->id), ['nolimit' => 1]);
            foreach ($courseSelections as $courseSelection) $courseSelection->delete();
            $student->delete();
        }
        $this->delete();
    }
}